package kiratest;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created by wangning on 2016/6/29.
 */

/*
设置超时限制
 */
public class Timeouts {
    private final OkHttpClient client;

    public Timeouts() throws Exception {
        client = new OkHttpClient.Builder()
                .connectTimeout(1, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .readTimeout(1, TimeUnit.SECONDS)
                .build();
    }
    @Test
    public void run() throws Exception {
        Request request = new Request.Builder()
                .url("http://httpbin.org/delay/2") // This URL is served with a 2 second delay.
                .build();

        Response response = client.newCall(request).execute();
        System.out.println("Response completed: " + response);
    }
}
